package com.sort;

import java.util.Arrays;

/*
* 选择排序
*
* */
public class Selection_Sort {
    public static void main(String[] args) {
        int[] arr = {23,12,31,1,13};
        new Selection_Sort().selectionSort(arr);
    }

    public void selectionSort(int[] arr){
        int[] copy = Arrays.copyOf(arr, arr.length);
        int l = copy.length;
        for (int i = 0; i < l; i++) {
            int max = 0;
            for (int j = 1; j < l-i; j++) {
                if(copy[max] < copy[j]){
                     max = j;
                }
            }
            if (max != l-1-i){
                int temp = copy[max];
                copy[max] = copy[l-1-i];
                copy[l-1-i] =temp;
            }

        }
        System.out.println(Arrays.toString(copy));
    }
}
